<template>
  <div>
    <!-- 头部 -->
    <div class="header">
      <div class="logo">
        <span class="iconfont iconnew"></span>
      </div>
      <div class="search">
        <span class="iconfont iconsearch"></span>
        <span>搜索新闻</span>
      </div>
      <div class="user">
        <span
          class="iconfont iconwode"
          style='font-size:20px'
        ></span>
      </div>
    </div>
    <!-- 导航栏 -->
    <van-tabs
      v-model="active"
      sticky
    >
      <van-tab
        :title="cate.name"
        v-for="cate in cateList"
        :key='cate.id'
      >
        <div
          class="single"
          @click="$router.push({path: `/postDetail/${post.id}`})"
          v-for="post in postList"
          :key="post.id"
        >
          <div class="left">
            <p class="content">{{post.title}}</p>
            <p class="info">
              <span>作者：{{post.user.nickname}}</span>
              <span>跟贴数：{{post.comment_length}}</span>
            </p>
          </div>
          <img
            :src="'http://210.21.98.31:6002' + post.cover[0].url"
            alt
          />

        </div>
      </van-tab>

    </van-tabs>
    <!-- 新闻列表-->
  </div>
</template>

<script>
// 引入axios
import axios from 'axios'
// import { Button } from 'vant'
export default {
  // comments: { 'van-button': Button }
  data() {
    return {
      active: 0,
      cateList: [],
      postList: []
    }
  },
  created() {
    axios
      .get('http://210.21.98.31:6002/category')
      .then(res => {
        //console.log(res)
        this.cateList = res.data.data
      })
      .catch(err => {
        console.log(err)
      })

    //获取默认栏目的新闻数据
    //axios.get('http://210.21.98.31:6002/post?category=999')
    axios.get('http://210.21.98.31:6002/post', { params: { category: 999 } }).then(res => {
      console.log(res)
      this.postList = res.data.data
    })
  }
}
</script>

<style lang="less" scoped>
@import url('http://at.alicdn.com/t/font_1426139_h6vn3jbl5q.css');

.header {
  height: 50px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 10px;
  background-color: #f00;

  .logo {
    color: #fff;

    .iconnew {
      font-size: 50px;
    }
  }

  .search {
    flex: 1;
    height: 40px;
    margin-top: 5px;
    border-radius: 20px;
    background-color: rgba(255, 255, 255, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
    margin: 0 10px;
  }

  .user {
    color: #fff;
    font-size: 20px;
  }
}
.single {
  padding: 15px 5px;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #ccc;
  flex-wrap: wrap;
  .left {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    overflow: hidden;
    .info {
      margin-top: 10px;
      font-size: 13px;
      color: #999;
      > span:nth-child(2) {
        margin-left: 10px;
      }
    }
  }
  img {
    width: 45px;
    height: 60px;
    padding-right: 20px;
    vertical-align: middle;
  }
}
</style>
